This repository was archived by the owner on May 15, 2026. It is now read-only.
fix: prevent crash when message.content is undefined in Anthropic API calls - #10954
Closed
ghost wants to merge 1 commit into
Closed
fix: prevent crash when message.content is undefined in Anthropic API calls#10954ghost wants to merge 1 commit into
ghost wants to merge 1 commit into
Conversation
- Add guard clause to check if message.content is undefined, null, or not an array - Prevents "Cannot read properties of undefined (reading filter)" error - Add comprehensive tests for edge cases (undefined, null, non-array, empty array) - Fixes issue reported in Reddit where Anthropic API calls would fail unexpectedly
Author
Review complete. No issues found. The implementation correctly adds a guard clause to handle Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Author
|
Closing this PR to investigate the root cause. The defensive fix treats the symptom (undefined content) rather than addressing why content is undefined in the first place, which violates the type contract. Will create a new PR after finding where malformed messages are being created. |
ghost
pushed a commit
that referenced
this pull request
Jan 25, 2026
…errors Root cause: JSON.parse() in readApiMessages() deserializes data with zero validation, allowing corrupted or legacy data to violate type contracts (e.g., undefined content). This causes downstream crashes in functions like filterNonAnthropicBlocks() that assume message.content is always string | ContentBlock[] per the type system, but receive undefined/null values from corrupted historical data. Solution: - Add validateApiMessage() to sanitize deserialized messages at the boundary - Fix undefined/null/non-array content by converting to empty array - Filter out malformed messages with invalid roles or non-object structure - Filter out invalid content blocks missing the required type field - Add comprehensive test coverage (12 tests covering all edge cases) Fixes: https://www.reddit.com/r/RooCode/s/yUXVFMYu3P Related to closed PR #10954 (which treated symptom, not cause)
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the "Cannot read properties of undefined (reading 'filter')" error reported in Reddit.
Problem
Users were experiencing API request failures when using Anthropic Claude models with the error:
The error occurred in
filterNonAnthropicBlocks()when attempting to filter message content that wasundefined,null, or not an array.Solution
Added a guard clause in
filterNonAnthropicBlocks()to check ifmessage.contentis:undefinednullIf any of these conditions are true, the message is filtered out gracefully rather than causing a crash.
Changes
filterNonAnthropicBlocks()Testing
All tests pass (13/13) including 4 new tests for edge cases.
View task on Roo Code Cloud
Important
Adds a guard clause in
filterNonAnthropicBlocks()to handleundefined,null, or non-arraymessage.content, preventing crashes and adding tests for these cases.filterNonAnthropicBlocks()inanthropic-filter.tsto handleundefined,null, or non-arraymessage.content.anthropic-filter.spec.tsfor edge cases:undefined,null, non-array, and empty array content.This description was created by
for 33687d9. You can customize this summary. It will automatically update as commits are pushed.